/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef, useEffect } from 'react';
import ProTable from '@ant-design/pro-table';
import type { ActionType } from '@ant-design/pro-table';
import type { StringObjType } from './index.d';
import { applyStatusOptions } from './index.d';
import { applyCommonColumn, applyFormColumn } from './index.d';
import { getAmountverifyList } from '@/services/finance_amountverify';

const AmountCashVerify: React.FC<{
  isShow: boolean;
  show: boolean;
  renewalApply: (data: StringObjType) => void;
}> = (props) => {
  const { renewalApply, isShow, show } = props;

  const actionRef = useRef<ActionType>();
  useEffect(() => {
    if (isShow && show && actionRef.current) {
      actionRef.current?.reloadAndRest?.();
    }
  }, [isShow, actionRef, show]);

  return (
    <ProTable<StringObjType>
      className='kb-pro-table'
      actionRef={actionRef}
      pagination={false}
      params={{
        isShow,
      }}
      rowKey='id'
      request={getAmountverifyList}
      columns={[
        ...applyFormColumn,
        ...applyCommonColumn,
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center',
          search: false,
          render: (_, record) => {
            const items = applyStatusOptions.find((item) => item.value == record.status);
            return <div style={{ color: items?.color }}>{items?.label}</div>;
          },
        },
        {
          title: '操作',
          dataIndex: 'operate',
          align: 'center',
          search: false,
          render: (_, record) => <a onClick={renewalApply.bind(null, record)}>再次申请</a>,
        },
      ]}
      options={false}
      scroll={{ x: 1200 }}
    />
  );
};

export default AmountCashVerify;
